<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 200px;
        height: 200px;
        background-color: skyblue;
        animation: colorChange 2s linear 2;
      }

      @keyframes colorChange {
        0%,
        100% {
          background-color: skyblue;
        }
        30% {
          background-color: #f00;
        }
        60% {
          background-color: #0f0;
        }
      }
    </style>
  </head>
  <body>
    <div class="box"></div>
    <script>
      const box = document.querySelector(".box");
      box.onanimationstart = function () {
        console.log("动画开始了哦~");
      };
      box.onanimationend = function () {
        console.log("动画结束了");
      };
      box.onanimationcancel = function () {
        console.log("动画被取消");
      };
      box.onanimationiteration = function () {
        console.log("当完成一次动画后触发");
      };
    </script>
  </body>
</html>

